/*
 * 天虹商场股份有限公司版权所有.
 */
package com.rainbow.hmkmybatis.session;


import com.rainbow.hmkmybatis.config.Configuration;
import com.rainbow.hmkmybatis.config.MapperRegistory;
import com.rainbow.hmkmybatis.executor.Executor;
import com.rainbow.hmkmybatis.mapper.MapperProxy;

import java.lang.reflect.Proxy;

/**
 * TODO
 *
 * @author 黄明坤
 * @version 1.0.0
 * @date 2020/6/28
 */
public class HMKSqlSession {

    private Configuration configuration;
    private Executor executor;

    public Configuration getConfiguration() {
        return configuration;
    }

    //关联起来
    public HMKSqlSession(Configuration configuration, Executor executor) {
        this.configuration = configuration;
        this.executor = executor;
    }

    public <T> T getMapper(Class<T> clazz) {
        return (T)Proxy.newProxyInstance(
                clazz.getClassLoader(),
                new Class[]{clazz},
                new MapperProxy(this,clazz));
    }

    public <T> T selectOne(MapperRegistory.MapperData mapperData, Object parameter) throws Exception {
        return executor.query(mapperData, parameter);
    }
}
